package com.example.administrator.liveapp.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.administrator.liveapp.ApplicationUtils;
import com.example.administrator.liveapp.R;

/**
 * 修改个人信息(单条)activity
 */

public class InputBoxPage extends AppCompatActivity implements View.OnClickListener {

    private int add;
    private TextView add_name;
    private TextView add_information;
    private EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input_box_page);
        ApplicationUtils applicationUtils = new ApplicationUtils();
        applicationUtils.addActivity(this);
        initView();
        initDate();
    }

    private void initDate() {
        Intent intent = getIntent();
        add_name.setText(intent.getStringExtra("title").toString());
        editText.setText(intent.getStringExtra("name").toString());
        add = intent.getIntExtra("result",0);
    }

    private void initView() {
        findViewById(R.id.cancel).setOnClickListener(this);
        findViewById(R.id.add_information).setOnClickListener(this);
        add_name = (TextView) findViewById(R.id.add_name);
        editText = (EditText) findViewById(R.id.editText);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.cancel:
                finish();
                break;
            case R.id.add_information:
                String name = editText.getText().toString();
                Intent data = new Intent(InputBoxPage.this,PersonalInformationPage.class);
                data.putExtra("add",name);
                setResult(add,data);
                finish();
                break;
            default:
                break;
        }
    }
}
